package com.mlh.controller;

import com.mlh.entity.User;
import com.mlh.enums.AppHttpCodeEnum;
import com.mlh.exception.SystemException;
import com.mlh.service.BlogLoginService;
import com.mlh.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 缪林辉
 * @date 2024/3/15 13:11
 * @DESCRIPTION
 */
@RestController
public class BlogLoginController {
    @Autowired
    private BlogLoginService blogLoginService;

    //登录接口
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        //验证用户输入是否有问题
        if(!StringUtils.hasText(user.getUserName())||!StringUtils.hasText(user.getPassword())){
            throw new SystemException(AppHttpCodeEnum.LOGIN_ERROR);
        }
        return blogLoginService.login(user);
    }

    //退出登录接口
    @PostMapping("/logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }
}
